let http = require('../../../utils/api.js');
import {
    myHttps,
    toData
} from '../../../utils/util.js';
const app = getApp()

Page({
    data: {
        length: '',//返回数据得长度
        arr: [],//所有数据
        hiddenLoading: false,
        current:1,
        size:10,//页容量
        userId:'',//用户id
    },
    onLoad: function (e) {
        this.setData({
            userId: e.userId
        })
        this.getComment(e.userId,this.data.current,this.data.size)
    },
    //事件处理函数
    // 请求所有的回复 走接口
    getComment(id,page,size) {
        let url = http.api.getComment +id +'/comments/replay?page='+page+'&size='+size;
        myHttps({
            url: url,
            method: "GET",
        }).then(res => {
            // console.log(res)
            if (res.code == 1) {
                for (var i = 0; i < res.data.content.length; i++) {
                    res.data.content[i].insert_time = toData(res.data.content[i].insert_time)
                    this.data.arr.push(res.data.content[i])
                }
                this.setData({
                    arr: this.data.arr,
                    hiddenLoading: true
                })
                // console.log(this.data.arr)
                wx.setNavigationBarTitle({
                    title: '回复我的（' + this.data.arr.length + '）' //页面标题为路由参数
                })
            }
        }).catch(err => {})
    },
        //下拉刷新从新初始化页码,条数
    onPullDownRefresh: function () {
        //下拉三个点消失
        wx.stopPullDownRefresh();
        this.setData({
            size: 10,
            current: 1,
            hiddenLoading: false
        })
        this.getComment(this.data.userId, this.data.current, this.data.size)
    },
    // 上拉加载五条数据
    onReachBottom: function () {
        this.setData({
            size: 10,
            current: this.data.current + 1,
            hiddenLoading: false
        })
        this.getComment(this.data.userId, this.data.current, this.data.size)
    },
})